package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.UpdateGroup;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.JxBannerEntity;
import io.renren.modules.sys.service.JxBannerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * banner
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2021-10-13 18:05:03
 */
@RestController
@RequestMapping("sys/jxbanner")
public class JxBannerController {
    @Autowired
    private JxBannerService jxBannerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:jxbanner:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = jxBannerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:jxbanner:info")
    public R info(@PathVariable("id") Long id){
        JxBannerEntity jxBanner = jxBannerService.getById(id);

        return R.ok().put("jxBanner", jxBanner);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:jxbanner:save")
    public R save(@RequestBody JxBannerEntity jxBanner){
        ValidatorUtils.validateEntity(jxBanner, AddGroup.class);
        jxBannerService.save(jxBanner);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:jxbanner:update")
    public R update(@RequestBody JxBannerEntity jxBanner){
        ValidatorUtils.validateEntity(jxBanner,UpdateGroup.class);
        jxBannerService.updateById(jxBanner);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:jxbanner:delete")
    public R delete(@RequestBody Long[] ids){
        jxBannerService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
